﻿using MqttClientNetLib;

int count = 0;

var mqttClient = MqttClientFactory.Create();

mqttClient.ClientOption(new MqClientOptionItem() {
    Ip = "192.168.210.201",
    Port = 1883,
    CleanSession = false,
    ClientId="Client1"
    
});
mqttClient.SubscribeOption(new MqClientSubscribeItem() {
    Topic = "A",
    Level = MqQosLevel.ExactlyOnce
});

mqttClient.StartAsync();

mqttClient.ReceiveCallback(msg =>
{
    Console.WriteLine("客户端1:" + msg.Payload);
});



Task.Run(async () =>
{
    while (true) {
        await Console.Out.WriteLineAsync($"client_1_B_{count}");
        await mqttClient.PublishStringAsync("B", $"client_1_B_{count}");
        await Task.Delay(1000);
        count++;
    }
});



Console.WriteLine("客户端1启动");
Console.ReadLine();